package com.thf.controller.product;

import com.alibaba.fastjson.JSON;
import com.thf.model.ResultData;
import com.thf.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Map;


@Controller
public class ProductFindAllController{
    @Resource
    private ProductService productService ;

    @RequestMapping("/product/findAll")
    @ResponseBody
    protected String productFindAll(Integer startPage, Integer pageSize , String val) throws ServletException, IOException {

//        PageModel pageMode = new PageModel(Tool.curPageToInt(startPage), Tool.pageSizeToInt(pageSize));
        Map map = JSON.parseObject(val,Map.class);
        //System.out.println(map);
        ResultData result = productService.productFindAll(startPage,pageSize,map);
//        System.out.println("查询------>"+result);

        //       反馈给前端--返回值
        String resJson = JSON.toJSONString(result);
        System.out.println(resJson);
//        resp.getWriter().println(resJson);
        return resJson ;

    }
}
